<template>
    <Header title="登录"></Header>
    <div class="register">
        <table>
            <tr>
                <td>用户名</td>
                <td>
                    <input class="user_name" v-model="user_name">
                </td>
            </tr>
            <tr>
                <td>密码：</td>
                <td>
                    <input type="password" class="user_pwd" v-model="pwd">
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <button @click="toRegister">注册</button>
                    <button @click="toLogin">去登录</button>
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import {reactive,toRefs} from 'vue'
import Header from '@/components/Header.vue'
import {useRouter} from 'vue-router'


const router = useRouter();


let data = reactive({
    username:'',
    pwd:''
})
    

    const{user_name,pwd} = {...toRefs(data)}
    
    function login(){

    
        if(localStorage.userInfo){
            const u = JSON.parse(localStorage.userInfo)
            if(u['user_name'] === user_name.value){
                if(U['pwd'] === pwd.value){
                    alert('登录成功')
                    localStorage.setItem('isLogin','1')
                    router.push('/home')
                }else{
                    alert('密码错误')
                }
            }else{
                alert('用户名或密码错误')
            }   
            else{
            alert('没有注册')
            router.push('/register')
            }
        }
    }
function toRegister() {
    router.push('/register');
}
</script>

<style>
</style>